<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
 * 你写下的每个字，都值得被温柔对待。
 * 
 * 你可以在<a href="https://amrx.me">静语·偶尔有风</a>获得更多关于此皮肤的信息
 * 
 * @package Restext Theme 
 * @author 简 / Jane
 * @version 1.0.0
 * @link https://amrx.me
 */
$this->need('header.php');
?>
        
        <main class="container">
            <section class="category-header">
                <div class="category-header-content">
                    <h1 class="category-title">
                        <?php $this->archiveTitle(array('category' => _t('%s')), '', ''); ?>
                        <em class="num"><?php echo $this->getTotal(); ?>篇</em>
                    </h1>
                    <?php if ($this->getDescription()): ?>
                    <p class="category-description">
                        <?php echo $this->getDescription(); ?>
                    </p>
                    <?php endif; ?>
                </div>
            </section>
            <article class="category-article-list category-<?php echo $this->getArchiveSlug(); ?>">
                <?php if ($this->have()): ?>
                <?php while($this->next()): ?>
                <?php if($this->fields->article_type == "Multi") { ?><!-- 多图样式 -->
                <?php
                    $content = $this->content;
                    $pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
                    preg_match_all($pattern, $content, $matches);
                                
                   $imageCount = count($matches[1]);
                   $maxImages = min($imageCount, 9);
                   ?>
                <li class="category-card">
                    <div class="category-album-container">
						<?php if($imageCount == 0):?>
                            <?php else:?>
                                <div class="postlist_album" num="<?php echo $imageCount;?>">
                                    <?php
                                        for ($i = 0; $i < $maxImages; $i++) {
                                            echo '<span data-fancybox="gallery'.$this->cid.'" class="postlist_gallery" href="'.$matches[1][$i].'"><img class="lazyload postlist_img" data-src="'.$matches[1][$i].'" alt="'.$this->title.'"><div class="dynamic-background"></div>';
                                            echo '</span>';
                                        }
                                    ?>
                                    <span class="photo-count">
                                        <svg height="1.2em" width="1.2em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="4" width="16" height="16" rx="1" stroke="currentColor" stroke-width="2"/><circle cx="10" cy="10" r="3" stroke="currentColor" stroke-width="2"/><path d="M20 16L14 10L6 18" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
                                        <span><?php echo countImagesInPost($this->content); ?> 张</span>
                                    </span>
                                </div>
                            <?php endif; ?>
					</div>
					<div class="category-album-content">
					    <h3 class="category-title line-clamp">
							<a href="<?php $this->permalink() ?>" class="bg-links"><?php $this->title() ?></a>
						</h3>
					</div>
                </li>
                <?php } else {?><!-- 默认样式 -->
                <li class="category-card">
                    <div class="category-thumbnail-container">
						<img data-src="<?php echo _getThumbnails($this)[0] ?>" alt="<?php $this->title() ?>封面图" class="category-thumbnail">
						<div class="dynamic-background"></div>
					</div>
					<div class="category-content">
					    <h3 class="category-title line-clamp">
							<a href="<?php $this->permalink() ?>" class="bg-links"><?php $this->title() ?></a>
						</h3>
						<p class="category-excerpt line-clamp">
						    <?php $this->excerpt(100, '...'); ?>
						</p>
						<div class="post-meta">
							<time class="post-date">
								<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="1.1em" width="1.1em"><path fill-rule="evenodd" d="M12 2.25c-5.385 0-9.75 4.365-9.75 9.75s4.365 9.75 9.75 9.75 9.75-4.365 9.75-9.75S17.385 2.25 12 2.25ZM12.75 6a.75.75 0 0 0-1.5 0v6c0 .414.336.75.75.75h4.5a.75.75 0 0 0 0-1.5h-3.75V6Z" clip-rule="evenodd"/></svg>
								<span>
									<?php echo formatTime($this->created); ?>
								</span>
							</time>
							<div>
								<span class="post-icon">
									<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="1.1em" width="1.1em"><path d="M4.804 21.644A6.707 6.707 0 0 0 6 21.75a6.721 6.721 0 0 0 3.583-1.029c.774.182 1.584.279 2.417.279 5.322 0 9.75-3.97 9.75-9 0-5.03-4.428-9-9.75-9s-9.75 3.97-9.75 9c0 2.409 1.025 4.587 2.674 6.192.232.226.277.428.254.543a3.73 3.73 0 0 1-.814 1.686.75.75 0 0 0 .44 1.223Z"/></svg>
								</span>
								<span class="comment-count">
									<?php $this->commentsNum('%d 条'); ?>
								</span>
							</div>
							<div>
								<span class="post-icon">
									<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" height="1.1em" width="1.1em"><path d="M12.963 2.286a.75.75 0 0 0-1.071-.136 9.742 9.742 0 0 0-3.539 6.176 7.547 7.547 0 0 1-1.705-1.715.75.75 0 0 0-1.152-.082A9 9 0 1 0 15.68 4.534a7.46 7.46 0 0 1-2.717-2.248ZM15.75 14.25a3.75 3.75 0 1 1-7.313-1.172c.628.465 1.35.81 2.133 1a5.99 5.99 0 0 1 1.925-3.546 3.75 3.75 0 0 1 3.255 3.718Z"/></svg>
								</span>
								<span class="post-views">
									<?php get_post_view($this) ?> °</span>
							</div>
						</div>
					</div>
                </li>
                <?php }?>
                <?php endwhile; ?>
                <?php else: ?>
                <span style="position:absolute;display:flex;justify-content:center;align-items:center;width:100%;height:calc(100vh - 6rem);color:var(--color-text-primary);">
                    暂无文章
                </span>
                <?php endif; ?>
            </article>
            <nav class="footer-nav">
                <?php $this->pageNav('<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 18l-6-6 6-6"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 18l6-6-6-6"/></svg>', 1, '...', array('wrapTag' => 'ol', 'wrapClass' => 'page-navigator', 'itemTag' => 'li', 'textTag' => 'span', 'currentClass' => 'current', 'prevClass' => 'prev', 'nextClass' => 'next',)); ?>
            </nav>
        </main>
    
    <?php $this->need('layout/footer.php');?>
    <?php $this->need('footer.php');?>
    
